package review.array;

/**
 * @Description @TODO
 * @Date 2025/7/21 15:56
 * @Created by weimeiling
 */
public class ArrayDemo {
    public static void main(String[] args) {
        reverseArray(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
    }

    public static void reverseArray(int[] arr) {
        for (int i = 0; i < arr.length / 2; i++) {
            int temp = arr[i];
            arr[i] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = temp;
        }
        printArray(arr);
    }

    public static void printArray(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }

    public void reverseArrayWhile(int[] arr) {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            // 交换元素
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
            left++;
            right--;
        }
        printArray(arr);
    }
}
